There are conventional techniques for calculating the attitude of a device using a magnetic sensor. For example, by detecting the direction of a magnetic field using a magnetic sensor, it is possible to calculate the attitude of a device with respect to the direction of the magnetic field.
Where the attitude of a device is calculated using a sensor, such as a magnetic sensor, which gives an output by detecting a value that is dependent on the attitude, the ability to precisely calculate the attitude is required.
Thus, the present disclosure provides a storage medium having information processing program stored thereon, an information processing device, an information processing system, and an attitude calculation method capable of precisely calculating the attitude of a device.
(1)
This application describes a non-transitory computer-readable storage medium storing an information processing program to be executed by a computer of an information processing device for calculating an attitude of an input unit having a magnetic sensor. The information processing program causes the computer to execute the following.
The computer obtains detected magnetic vectors detected by the magnetic sensor. The computer stores the detected magnetic vectors in a storage unit while classifying each detected magnetic vector based on a direction from a reference position, which is determined based on the detected magnetic vector, to the end point position of the detected magnetic vector. The computer estimates a center position of a spherical body having a curved surface which is estimated based on the end point positions of detected magnetic vectors obtained by extracting, from among the classified detected magnetic vectors, at least one detected magnetic vector for each class. The computer calculates the attitude of the input unit based on a direction vector representing a direction from the center position to the end point position of the detected magnetic vector.
With configuration (1) above, each detected magnetic vector is classified based on the direction from the reference position to the end point of the detected magnetic vector. Now, by using direction vectors extending in various directions, it is likely that the estimated center position is calculated more accurately. That is, by classifying each detected magnetic vector based on the direction from the reference position to the end point of the detected magnetic vector, as in configuration (1) above, it is possible to estimate the center position using detected magnetic vectors extending in various directions. Thus, it is possible to accurately estimate the center position, and therefore to precisely calculate the attitude of the input unit.
(2)
The computer may set a plurality of categories based on a direction from a reference position, which is defined based on the detected magnetic vectors, to the end point positions of the detected magnetic vectors, and classify a newly-obtained detected magnetic vector into one of the categories based on a direction from the reference position to the end point position of the newly-obtained detected magnetic vector.
With configuration (2) above, each detected magnetic vector obtained is classified into a category based on the direction from the reference position to the end point position of the detected magnetic vector, whereby detected magnetic vectors extending in various directions can be more reliably used as detected magnetic vectors for estimating the center position.
(3)
The computer may store one detected magnetic vector obtained from each set of one or more detected magnetic vectors belonging to the same class in the storage unit. Then, the computer estimates a center position of a spherical body having a curved surface which is estimated based on the end point positions of the detected magnetic vectors stored in the storage unit.
With configuration (3) above, the number of detected magnetic vectors stored in the storage unit can be limited to a certain number, and it is therefore possible to reduce the data size of the area in the storage unit for storing the detected magnetic vectors.
(4)
If a detected magnetic vector belonging to the same class as a newly-obtained detected magnetic vector has already been stored, the computer may store the newly-obtained detected magnetic vector, overwriting the already-stored detected magnetic vector.
With configuration (4) above, where a detected magnetic vector of an abnormal value has been stored, if a detected magnetic vector of a normal value is thereafter obtained, the detected magnetic vector of an abnormal value can be overwritten with the detected magnetic vector of a normal value. Therefore, it is possible to calculate the center position while eliminating the influence of a detected magnetic vector of an abnormal value, and it is possible to more precisely calculate the center position.
(5)
If a detected magnetic vector belonging to the same class as a newly-obtained detected magnetic vector has already been stored, the computer may store a detected magnetic vector which is produced based on the already-stored detected magnetic vector and the newly-obtained detected magnetic vector.
With configuration (5) above, where a detected magnetic vector of an abnormal value has been stored, if a detected magnetic vector of a normal value is thereafter obtained, the influence of the detected magnetic vector of an abnormal value is decreased by the detected magnetic vector of a normal value. Therefore, it is possible to calculate the center position while decreasing the influence of detected magnetic vectors of abnormal values, and it is possible to more precisely calculate the center position.
(6)
The information processing program may cause the computer to further execute setting the reference position on, or on an inner side of, a surface of the spherical body.
With configuration (6) above, since detected magnetic vectors corresponding to direction vectors extending in various directions can be stored, it is possible to estimate the center position more accurately.
(7)
After the center position is calculated, each time a detected magnetic vector is obtained, the computer may store the obtained detected magnetic vector while using, as the reference position, a latest center position.
With configuration (7) above, since it is possible to calculate the center position based on the latest detected magnetic vector, it is possible to more precisely calculate the center position. Thus, it is possible to obtain more accurate direction vectors for use in the classification, and it is possible to more precisely calculate the attitude.
(8)
The computer may update the center position each time a detected magnetic vector is newly stored.
With configuration (8) above, since the center position and the reference position are updated each time a detected magnetic vector is obtained, it is possible to obtain more accurate direction vectors for use in the classification.
(9)
For each detected magnetic vector, the computer may select a classification vector extending in a direction closest to a direction from the reference position to the end point of the detected magnetic vector from among a plurality of classification vectors extending in different directions from one another, and classify detected magnetic vectors for which different classification vectors are selected into different categories.
With configuration (9) above, the detected magnetic vectors can be easily classified by using the classification vectors.
(10)
Where the plurality of classification vectors are arranged so that the start points thereof are at a center of a sphere, the classification vectors may be arranged so that the end points of the classification vectors are evenly dispersed across a spherical surface of the sphere or across a half of the spherical surface.
With configuration (10) above, evenly-dispersed detected magnetic vectors can be stored in the storage unit. Therefore, it is possible to more accurately estimate the center position, and it is possible to more precisely calculate the attitude.
(11)
The computer may select a classification vector based on an absolute value of an inner product between the classification vector and a vector representing a direction from the reference position to the end point position of the detected magnetic vector, and further classify detected magnetic vectors associated with the same classification vector into different categories depending on a sign of the inner product.
With configuration (11) above, it is possible to reduce in half the number of times the inner product is calculated for the selection of a classification vector, and it is therefore possible to classify detected magnetic vectors more quickly.
Note that the present specification discloses an information processing device and an information processing system including various units that are equivalent to various units implemented by executing the information processing program recited in configurations (1) to (11) above, and also discloses an attitude calculation method to be carried out in configurations (1) to (11).
With the storage medium having information processing program stored thereon, the information processing device, the information processing system and the attitude calculation method, each detected magnetic vector is classified based on the direction from the reference position to the end point of the detected magnetic vector, whereby the center position is easily calculated using detected magnetic vectors extending in various directions. Thus, it is possible to more accurately estimate the center position, and therefore to precisely calculate the attitude of the input unit.
These and other objects, features, aspects and advantages will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings.